import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ConfigService } from '@nestjs/config';
import { Logger } from '@nestjs/common';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const config = app.get(ConfigService);

  app.enableCors({ origin: true, credentials: true });

  const globalPrefixRaw = config.get<string>('GLOBAL_PREFIX', '/api');
  const normalizedPrefix = (globalPrefixRaw || '').replace(/^\/+|\/+$/g, '');
  if (normalizedPrefix) app.setGlobalPrefix(normalizedPrefix);

  const port = config.get<number>('UPLOADER_APP_PORT', 8100);
  await app.listen(port);
  Logger.log(`File uploader is running on port ${port}`);
}

bootstrap();


